package com.bluesky.example.concurrent;

public class Consumer extends Thread {

	Buffer buf;
	volatile int n;

	public Consumer(Buffer buf, int n,int number) {
		this.buf = buf;
		this.n = n;
		
		setName("consumer"+number);
	}

	@Override
	public void run() {
		while (!buf.isClosed() ) {
			n--;
			Object o = buf.get();

			if(o==null)
				break;
			// echo it
			System.out.println("consumer" + hashCode() + " comsuming:" + o);

		}

		System.out.println("consumer" + hashCode() + " end");

	}

}
